<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<script>
    function getMessage() {
        // 实例化一个 xmlHttpRequest
        var request = new XMLHttpRequest();
        // 设置 xmlHttpRequest 对象的回调函数
        // request.readState 1 2 3 4
        // request.status 响应状态码 响应行状态码
        request.onreadystatechange = function (){
            if (request.readyState == 4 && request.status == 200) {
                // 接收响应结果，处理结果
                // 将响应放到指定的位置
                var inputEle = document.getElementById("message");
                inputEle.value = request.responseText;
            }
        }
        // 设置发送请求的方式和请求的资源路径
        request.open("GET", "/hello?username=zhangsan");
        // 发送请求
        request.send();
    }
</script>
</head>
<body>
<button onclick="getMessage()">按钮</button>
<input type = "text" id = "message" />
</body>
</html>